
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 05/24/2013 09:16:42
-- Generated from EDMX file: C:\Users\lfernandez2\Documents\adevso-google\SmartParking\SmartParking.Data\SmartParking.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [SmartParkingTesting];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_Logs_Managers]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Logs] DROP CONSTRAINT [FK_Logs_Managers];
GO
IF OBJECT_ID(N'[dbo].[FK_ManagerParkingZones_Managers]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ManagerParkingZones] DROP CONSTRAINT [FK_ManagerParkingZones_Managers];
GO
IF OBJECT_ID(N'[dbo].[FK_ManagerParkingZones_ParkingZones]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ManagerParkingZones] DROP CONSTRAINT [FK_ManagerParkingZones_ParkingZones];
GO
IF OBJECT_ID(N'[dbo].[FK_Managers_Customers]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Managers] DROP CONSTRAINT [FK_Managers_Customers];
GO
IF OBJECT_ID(N'[dbo].[FK_Managers_Roles]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Managers] DROP CONSTRAINT [FK_Managers_Roles];
GO
IF OBJECT_ID(N'[dbo].[FK_OrderDetails_Orders]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrderDetails] DROP CONSTRAINT [FK_OrderDetails_Orders];
GO
IF OBJECT_ID(N'[dbo].[FK_OrderDetails_ParkingZones]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrderDetails] DROP CONSTRAINT [FK_OrderDetails_ParkingZones];
GO
IF OBJECT_ID(N'[dbo].[FK_Orders_PrepaidCards]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Orders] DROP CONSTRAINT [FK_Orders_PrepaidCards];
GO
IF OBJECT_ID(N'[dbo].[FK_Orders_Users]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Orders] DROP CONSTRAINT [FK_Orders_Users];
GO
IF OBJECT_ID(N'[dbo].[FK_Parkings_Customers]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Parkings] DROP CONSTRAINT [FK_Parkings_Customers];
GO
IF OBJECT_ID(N'[dbo].[FK_ParkingZoneFares_ParkingZones]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ParkingZoneFares] DROP CONSTRAINT [FK_ParkingZoneFares_ParkingZones];
GO
IF OBJECT_ID(N'[dbo].[FK_ParkingZones_Parkings]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ParkingZones] DROP CONSTRAINT [FK_ParkingZones_Parkings];
GO
IF OBJECT_ID(N'[dbo].[FK_ParkingZoneSpaces_ParkingZones]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ParkingZoneSpaces] DROP CONSTRAINT [FK_ParkingZoneSpaces_ParkingZones];
GO
IF OBJECT_ID(N'[dbo].[FK_PrepaidCardDetails_PrepaidCards]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PrepaidCardDetails] DROP CONSTRAINT [FK_PrepaidCardDetails_PrepaidCards];
GO
IF OBJECT_ID(N'[dbo].[FK_ProcessingReservations_ParkingZones]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProcessingReservations] DROP CONSTRAINT [FK_ProcessingReservations_ParkingZones];
GO
IF OBJECT_ID(N'[dbo].[FK_RolePermissions_Permissions]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RolePermissions] DROP CONSTRAINT [FK_RolePermissions_Permissions];
GO
IF OBJECT_ID(N'[dbo].[FK_RolePermissions_Roles]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RolePermissions] DROP CONSTRAINT [FK_RolePermissions_Roles];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Customers]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Customers];
GO
IF OBJECT_ID(N'[dbo].[Logs]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Logs];
GO
IF OBJECT_ID(N'[dbo].[ManagerParkingZones]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ManagerParkingZones];
GO
IF OBJECT_ID(N'[dbo].[Managers]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Managers];
GO
IF OBJECT_ID(N'[dbo].[OrderDetails]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OrderDetails];
GO
IF OBJECT_ID(N'[dbo].[Orders]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Orders];
GO
IF OBJECT_ID(N'[dbo].[Parkings]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Parkings];
GO
IF OBJECT_ID(N'[dbo].[ParkingZoneFares]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ParkingZoneFares];
GO
IF OBJECT_ID(N'[dbo].[ParkingZones]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ParkingZones];
GO
IF OBJECT_ID(N'[dbo].[ParkingZoneSpaces]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ParkingZoneSpaces];
GO
IF OBJECT_ID(N'[dbo].[Permissions]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Permissions];
GO
IF OBJECT_ID(N'[dbo].[PrepaidCardDetails]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PrepaidCardDetails];
GO
IF OBJECT_ID(N'[dbo].[PrepaidCards]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PrepaidCards];
GO
IF OBJECT_ID(N'[dbo].[ProcessingReservations]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProcessingReservations];
GO
IF OBJECT_ID(N'[dbo].[RolePermissions]', 'U') IS NOT NULL
    DROP TABLE [dbo].[RolePermissions];
GO
IF OBJECT_ID(N'[dbo].[Roles]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Roles];
GO
IF OBJECT_ID(N'[dbo].[Users]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Users];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Customers'
CREATE TABLE [dbo].[Customers] (
    [CustomerID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Email] nvarchar(100)  NOT NULL,
    [Phone] nvarchar(12)  NOT NULL,
    [Address] nvarchar(max)  NOT NULL,
    [Deleted] bit  NOT NULL
);
GO

-- Creating table 'Logs'
CREATE TABLE [dbo].[Logs] (
    [LogID] bigint IDENTITY(1,1) NOT NULL,
    [ManagerID] int  NOT NULL,
    [Action] nvarchar(75)  NOT NULL,
    [AffectedTable] nvarchar(30)  NOT NULL,
    [AffectedID] nvarchar(15)  NOT NULL,
    [Message] nvarchar(max)  NULL,
    [IPAddress] nvarchar(15)  NOT NULL,
    [Date] datetime  NOT NULL
);
GO

-- Creating table 'ManagerParkingZones'
CREATE TABLE [dbo].[ManagerParkingZones] (
    [ManagerID] int  NOT NULL,
    [ParkingID] int  NOT NULL,
    [ParkingZoneID] int  NOT NULL,
    [Deleted] bit  NOT NULL
);
GO

-- Creating table 'Managers'
CREATE TABLE [dbo].[Managers] (
    [ManagerID] int IDENTITY(1,1) NOT NULL,
    [CustomerID] int  NOT NULL,
    [RoleID] int  NOT NULL,
    [UserName] nvarchar(15)  NOT NULL,
    [Password] nvarchar(50)  NOT NULL,
    [Email] nvarchar(100)  NOT NULL,
    [Phone] nvarchar(12)  NOT NULL,
    [Deleted] bit  NOT NULL
);
GO

-- Creating table 'OrderDetails'
CREATE TABLE [dbo].[OrderDetails] (
    [OrderID] nvarchar(18)  NOT NULL,
    [OrderDetailID] int  NOT NULL,
    [ParkingID] int  NOT NULL,
    [ParkingZoneID] int  NOT NULL,
    [CarPlate] nvarchar(10)  NOT NULL,
    [StartDateTime] datetime  NULL,
    [EndDateTime] datetime  NULL,
    [ReservationStartDateTime] datetime  NULL,
    [ReservationEndDateTime] datetime  NULL,
    [Amount] decimal(15,3)  NULL,
    [Commission] decimal(15,3)  NULL,
    [Deleted] bit  NOT NULL
);
GO

-- Creating table 'Orders'
CREATE TABLE [dbo].[Orders] (
    [OrderID] nvarchar(18)  NOT NULL,
    [UserID] bigint  NULL,
    [DateTime] datetime  NOT NULL,
    [TotalAmount] decimal(15,3)  NOT NULL,
    [TotalCommission] decimal(15,3)  NOT NULL,
    [IsReservation] bit  NOT NULL,
    [PaymentType] nvarchar(11)  NOT NULL,
    [PrepaidCardID] uniqueidentifier  NULL,
    [CCAuthorization] nvarchar(20)  NULL,
    [Status] nvarchar(1)  NOT NULL,
    [IPAddress] nvarchar(15)  NOT NULL,
    [Deleted] bit  NOT NULL
);
GO

-- Creating table 'Parkings'
CREATE TABLE [dbo].[Parkings] (
    [ParkingID] int IDENTITY(1,1) NOT NULL,
    [CustomerID] int  NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [LegalID] nvarchar(10)  NULL,
    [LegalName] nvarchar(50)  NULL,
    [BankAccountNumber] nvarchar(17)  NULL,
    [Address] nvarchar(50)  NULL,
    [Phone] nvarchar(12)  NULL,
    [Deleted] bit  NOT NULL
);
GO

-- Creating table 'ParkingZoneFares'
CREATE TABLE [dbo].[ParkingZoneFares] (
    [ParkingID] int  NOT NULL,
    [ParkingZoneID] int  NOT NULL,
    [ParkingZoneFareID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(15)  NOT NULL,
    [PriceHour] decimal(15,3)  NOT NULL,
    [Deleted] bit  NOT NULL
);
GO

-- Creating table 'ParkingZones'
CREATE TABLE [dbo].[ParkingZones] (
    [ParkingID] int  NOT NULL,
    [ParkingZoneID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(30)  NOT NULL,
    [ManagerCommisionAmount] decimal(15,3)  NOT NULL,
    [WebCommisionAmount] decimal(15,3)  NOT NULL,
    [AllowHalfHour] bit  NOT NULL,
    [OpenHour] nvarchar(6)  NOT NULL,
    [CloseHour] nvarchar(6)  NOT NULL,
    [RegularSpaces] int  NOT NULL,
    [SpacesToReserve] int  NOT NULL,
    [Deleted] bit  NOT NULL
);
GO

-- Creating table 'ParkingZoneSpaces'
CREATE TABLE [dbo].[ParkingZoneSpaces] (
    [ParkingID] int  NOT NULL,
    [ParkingZoneID] int  NOT NULL,
    [ParkingZoneSpaceID] int  NOT NULL,
    [Available] bit  NOT NULL,
    [Deleted] bit  NOT NULL
);
GO

-- Creating table 'Permissions'
CREATE TABLE [dbo].[Permissions] (
    [PermissionID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Deleted] bit  NOT NULL
);
GO

-- Creating table 'PrepaidCards'
CREATE TABLE [dbo].[PrepaidCards] (
    [PrepaidCardID] uniqueidentifier  NOT NULL,
    [Activated] bit  NOT NULL,
    [Balance] decimal(15,3)  NOT NULL,
    [CreationDate] datetime  NOT NULL,
    [ModifiedDate] datetime  NOT NULL,
    [Deleted] bit  NOT NULL
);
GO

-- Creating table 'RolePermissions'
CREATE TABLE [dbo].[RolePermissions] (
    [RoleID] int  NOT NULL,
    [PermissionID] int  NOT NULL
);
GO

-- Creating table 'Roles'
CREATE TABLE [dbo].[Roles] (
    [RoleID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(25)  NOT NULL,
    [Deleted] bit  NOT NULL
);
GO

-- Creating table 'Users'
CREATE TABLE [dbo].[Users] (
    [UserID] bigint IDENTITY(1,1) NOT NULL,
    [Email] nvarchar(100)  NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [LastName] nvarchar(50)  NOT NULL,
    [Password] nvarchar(50)  NOT NULL,
    [ReceiveInfo] bit  NOT NULL,
    [Deleted] bit  NOT NULL
);
GO

-- Creating table 'PrepaidCardDetails'
CREATE TABLE [dbo].[PrepaidCardDetails] (
    [PrepaidCardDetailsID] int IDENTITY(1,1) NOT NULL,
    [PrepaidCardID] uniqueidentifier  NOT NULL,
    [Amount] decimal(15,3)  NOT NULL,
    [Description] nvarchar(75)  NOT NULL,
    [DateTime] datetime  NOT NULL,
    [Deleted] bit  NOT NULL
);
GO

-- Creating table 'ProcessingReservations'
CREATE TABLE [dbo].[ProcessingReservations] (
    [ProcessingReservationsID] int IDENTITY(1,1) NOT NULL,
    [SessionID] nvarchar(30)  NOT NULL,
    [ParkingID] int  NOT NULL,
    [ParkingZoneID] int  NOT NULL,
    [CarPlate] nvarchar(10)  NOT NULL,
    [StartDateTime] datetime  NULL,
    [EndDateTime] datetime  NULL,
    [ReservationStartDateTime] datetime  NULL,
    [ReservationEndDateTime] datetime  NULL,
    [Amount] decimal(15,3)  NULL,
    [Commission] decimal(15,3)  NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [CustomerID] in table 'Customers'
ALTER TABLE [dbo].[Customers]
ADD CONSTRAINT [PK_Customers]
    PRIMARY KEY CLUSTERED ([CustomerID] ASC);
GO

-- Creating primary key on [LogID] in table 'Logs'
ALTER TABLE [dbo].[Logs]
ADD CONSTRAINT [PK_Logs]
    PRIMARY KEY CLUSTERED ([LogID] ASC);
GO

-- Creating primary key on [ManagerID], [ParkingID], [ParkingZoneID] in table 'ManagerParkingZones'
ALTER TABLE [dbo].[ManagerParkingZones]
ADD CONSTRAINT [PK_ManagerParkingZones]
    PRIMARY KEY CLUSTERED ([ManagerID], [ParkingID], [ParkingZoneID] ASC);
GO

-- Creating primary key on [ManagerID] in table 'Managers'
ALTER TABLE [dbo].[Managers]
ADD CONSTRAINT [PK_Managers]
    PRIMARY KEY CLUSTERED ([ManagerID] ASC);
GO

-- Creating primary key on [OrderID], [OrderDetailID] in table 'OrderDetails'
ALTER TABLE [dbo].[OrderDetails]
ADD CONSTRAINT [PK_OrderDetails]
    PRIMARY KEY CLUSTERED ([OrderID], [OrderDetailID] ASC);
GO

-- Creating primary key on [OrderID] in table 'Orders'
ALTER TABLE [dbo].[Orders]
ADD CONSTRAINT [PK_Orders]
    PRIMARY KEY CLUSTERED ([OrderID] ASC);
GO

-- Creating primary key on [ParkingID] in table 'Parkings'
ALTER TABLE [dbo].[Parkings]
ADD CONSTRAINT [PK_Parkings]
    PRIMARY KEY CLUSTERED ([ParkingID] ASC);
GO

-- Creating primary key on [ParkingID], [ParkingZoneID], [ParkingZoneFareID] in table 'ParkingZoneFares'
ALTER TABLE [dbo].[ParkingZoneFares]
ADD CONSTRAINT [PK_ParkingZoneFares]
    PRIMARY KEY CLUSTERED ([ParkingID], [ParkingZoneID], [ParkingZoneFareID] ASC);
GO

-- Creating primary key on [ParkingID], [ParkingZoneID] in table 'ParkingZones'
ALTER TABLE [dbo].[ParkingZones]
ADD CONSTRAINT [PK_ParkingZones]
    PRIMARY KEY CLUSTERED ([ParkingID], [ParkingZoneID] ASC);
GO

-- Creating primary key on [ParkingID], [ParkingZoneID], [ParkingZoneSpaceID] in table 'ParkingZoneSpaces'
ALTER TABLE [dbo].[ParkingZoneSpaces]
ADD CONSTRAINT [PK_ParkingZoneSpaces]
    PRIMARY KEY CLUSTERED ([ParkingID], [ParkingZoneID], [ParkingZoneSpaceID] ASC);
GO

-- Creating primary key on [PermissionID] in table 'Permissions'
ALTER TABLE [dbo].[Permissions]
ADD CONSTRAINT [PK_Permissions]
    PRIMARY KEY CLUSTERED ([PermissionID] ASC);
GO

-- Creating primary key on [PrepaidCardID] in table 'PrepaidCards'
ALTER TABLE [dbo].[PrepaidCards]
ADD CONSTRAINT [PK_PrepaidCards]
    PRIMARY KEY CLUSTERED ([PrepaidCardID] ASC);
GO

-- Creating primary key on [RoleID], [PermissionID] in table 'RolePermissions'
ALTER TABLE [dbo].[RolePermissions]
ADD CONSTRAINT [PK_RolePermissions]
    PRIMARY KEY NONCLUSTERED ([RoleID], [PermissionID] ASC);
GO

-- Creating primary key on [RoleID] in table 'Roles'
ALTER TABLE [dbo].[Roles]
ADD CONSTRAINT [PK_Roles]
    PRIMARY KEY CLUSTERED ([RoleID] ASC);
GO

-- Creating primary key on [UserID] in table 'Users'
ALTER TABLE [dbo].[Users]
ADD CONSTRAINT [PK_Users]
    PRIMARY KEY CLUSTERED ([UserID] ASC);
GO

-- Creating primary key on [PrepaidCardDetailsID] in table 'PrepaidCardDetails'
ALTER TABLE [dbo].[PrepaidCardDetails]
ADD CONSTRAINT [PK_PrepaidCardDetails]
    PRIMARY KEY CLUSTERED ([PrepaidCardDetailsID] ASC);
GO

-- Creating primary key on [ProcessingReservationsID] in table 'ProcessingReservations'
ALTER TABLE [dbo].[ProcessingReservations]
ADD CONSTRAINT [PK_ProcessingReservations]
    PRIMARY KEY CLUSTERED ([ProcessingReservationsID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [CustomerID] in table 'Managers'
ALTER TABLE [dbo].[Managers]
ADD CONSTRAINT [FK_Managers_Customers]
    FOREIGN KEY ([CustomerID])
    REFERENCES [dbo].[Customers]
        ([CustomerID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Managers_Customers'
CREATE INDEX [IX_FK_Managers_Customers]
ON [dbo].[Managers]
    ([CustomerID]);
GO

-- Creating foreign key on [CustomerID] in table 'Parkings'
ALTER TABLE [dbo].[Parkings]
ADD CONSTRAINT [FK_Parkings_Customers]
    FOREIGN KEY ([CustomerID])
    REFERENCES [dbo].[Customers]
        ([CustomerID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Parkings_Customers'
CREATE INDEX [IX_FK_Parkings_Customers]
ON [dbo].[Parkings]
    ([CustomerID]);
GO

-- Creating foreign key on [ManagerID] in table 'Logs'
ALTER TABLE [dbo].[Logs]
ADD CONSTRAINT [FK_Logs_Managers]
    FOREIGN KEY ([ManagerID])
    REFERENCES [dbo].[Managers]
        ([ManagerID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Logs_Managers'
CREATE INDEX [IX_FK_Logs_Managers]
ON [dbo].[Logs]
    ([ManagerID]);
GO

-- Creating foreign key on [ManagerID] in table 'ManagerParkingZones'
ALTER TABLE [dbo].[ManagerParkingZones]
ADD CONSTRAINT [FK_ManagerParkingZones_Managers]
    FOREIGN KEY ([ManagerID])
    REFERENCES [dbo].[Managers]
        ([ManagerID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [ParkingID], [ParkingZoneID] in table 'ManagerParkingZones'
ALTER TABLE [dbo].[ManagerParkingZones]
ADD CONSTRAINT [FK_ManagerParkingZones_ParkingZones]
    FOREIGN KEY ([ParkingID], [ParkingZoneID])
    REFERENCES [dbo].[ParkingZones]
        ([ParkingID], [ParkingZoneID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ManagerParkingZones_ParkingZones'
CREATE INDEX [IX_FK_ManagerParkingZones_ParkingZones]
ON [dbo].[ManagerParkingZones]
    ([ParkingID], [ParkingZoneID]);
GO

-- Creating foreign key on [RoleID] in table 'Managers'
ALTER TABLE [dbo].[Managers]
ADD CONSTRAINT [FK_Managers_Roles]
    FOREIGN KEY ([RoleID])
    REFERENCES [dbo].[Roles]
        ([RoleID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Managers_Roles'
CREATE INDEX [IX_FK_Managers_Roles]
ON [dbo].[Managers]
    ([RoleID]);
GO

-- Creating foreign key on [OrderID] in table 'OrderDetails'
ALTER TABLE [dbo].[OrderDetails]
ADD CONSTRAINT [FK_OrderDetails_Orders]
    FOREIGN KEY ([OrderID])
    REFERENCES [dbo].[Orders]
        ([OrderID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [ParkingID], [ParkingZoneID] in table 'OrderDetails'
ALTER TABLE [dbo].[OrderDetails]
ADD CONSTRAINT [FK_OrderDetails_ParkingZones]
    FOREIGN KEY ([ParkingID], [ParkingZoneID])
    REFERENCES [dbo].[ParkingZones]
        ([ParkingID], [ParkingZoneID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrderDetails_ParkingZones'
CREATE INDEX [IX_FK_OrderDetails_ParkingZones]
ON [dbo].[OrderDetails]
    ([ParkingID], [ParkingZoneID]);
GO

-- Creating foreign key on [PrepaidCardID] in table 'Orders'
ALTER TABLE [dbo].[Orders]
ADD CONSTRAINT [FK_Orders_PrepaidCards]
    FOREIGN KEY ([PrepaidCardID])
    REFERENCES [dbo].[PrepaidCards]
        ([PrepaidCardID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Orders_PrepaidCards'
CREATE INDEX [IX_FK_Orders_PrepaidCards]
ON [dbo].[Orders]
    ([PrepaidCardID]);
GO

-- Creating foreign key on [UserID] in table 'Orders'
ALTER TABLE [dbo].[Orders]
ADD CONSTRAINT [FK_Orders_Users]
    FOREIGN KEY ([UserID])
    REFERENCES [dbo].[Users]
        ([UserID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Orders_Users'
CREATE INDEX [IX_FK_Orders_Users]
ON [dbo].[Orders]
    ([UserID]);
GO

-- Creating foreign key on [ParkingID] in table 'ParkingZones'
ALTER TABLE [dbo].[ParkingZones]
ADD CONSTRAINT [FK_ParkingZones_Parkings]
    FOREIGN KEY ([ParkingID])
    REFERENCES [dbo].[Parkings]
        ([ParkingID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [ParkingID], [ParkingZoneID] in table 'ParkingZoneFares'
ALTER TABLE [dbo].[ParkingZoneFares]
ADD CONSTRAINT [FK_ParkingZoneFares_ParkingZones]
    FOREIGN KEY ([ParkingID], [ParkingZoneID])
    REFERENCES [dbo].[ParkingZones]
        ([ParkingID], [ParkingZoneID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [ParkingID], [ParkingZoneID] in table 'ParkingZoneSpaces'
ALTER TABLE [dbo].[ParkingZoneSpaces]
ADD CONSTRAINT [FK_ParkingZoneSpaces_ParkingZones]
    FOREIGN KEY ([ParkingID], [ParkingZoneID])
    REFERENCES [dbo].[ParkingZones]
        ([ParkingID], [ParkingZoneID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [PermissionID] in table 'RolePermissions'
ALTER TABLE [dbo].[RolePermissions]
ADD CONSTRAINT [FK_RolePermissions_Permissions]
    FOREIGN KEY ([PermissionID])
    REFERENCES [dbo].[Permissions]
        ([PermissionID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_RolePermissions_Permissions'
CREATE INDEX [IX_FK_RolePermissions_Permissions]
ON [dbo].[RolePermissions]
    ([PermissionID]);
GO

-- Creating foreign key on [RoleID] in table 'RolePermissions'
ALTER TABLE [dbo].[RolePermissions]
ADD CONSTRAINT [FK_RolePermissions_Roles]
    FOREIGN KEY ([RoleID])
    REFERENCES [dbo].[Roles]
        ([RoleID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [PrepaidCardID] in table 'PrepaidCardDetails'
ALTER TABLE [dbo].[PrepaidCardDetails]
ADD CONSTRAINT [FK_PrepaidCardDetails_PrepaidCards]
    FOREIGN KEY ([PrepaidCardID])
    REFERENCES [dbo].[PrepaidCards]
        ([PrepaidCardID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PrepaidCardDetails_PrepaidCards'
CREATE INDEX [IX_FK_PrepaidCardDetails_PrepaidCards]
ON [dbo].[PrepaidCardDetails]
    ([PrepaidCardID]);
GO

-- Creating foreign key on [ParkingID], [ParkingZoneID] in table 'ProcessingReservations'
ALTER TABLE [dbo].[ProcessingReservations]
ADD CONSTRAINT [FK_ProcessingReservations_ParkingZones]
    FOREIGN KEY ([ParkingID], [ParkingZoneID])
    REFERENCES [dbo].[ParkingZones]
        ([ParkingID], [ParkingZoneID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProcessingReservations_ParkingZones'
CREATE INDEX [IX_FK_ProcessingReservations_ParkingZones]
ON [dbo].[ProcessingReservations]
    ([ParkingID], [ParkingZoneID]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------